//
//  CMHomeCtrl.m
//  CreditManger
//
//  Created by sky on 15/10/30.
//  Copyright © 2015年 jinxin. All rights reserved.
//

#import "CMHomeCtrl.h"
#import "UIImageView+WebCache.h"
#import "CMBankLoginCtrl.h"
#import "CMLoginManager.h"
#import "CMMyCenterCtrl.h"
#import "CMBankRegistCtrl.h"


@interface CMHomeCtrl (){
    UIImageView *_headview;
    UILabel *_phonenum;
    UIImageView *_certview;
    UIImage *_cert;
    UIImage *_notcert;
    UILabel *_certlbl;
    UIImageView *_certjiantou;
}

@end

@implementation CMHomeCtrl

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}


-(void)buildLayout{
    
    [self showDoneWithTitle:@"我的"];
    
    self.title = @"个人首页";
    UIImage *headbg = [UIImage imageNamed:@"home_bg"];
    UIImageView *hebgview = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, headbg.size.height)];
    hebgview.image = headbg;
    [self.view addSubview:hebgview];
    
    UIImage *headim = [UIImage imageNamed:@"head_place"];
    _headview = [[UIImageView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH/2 - headim.size.width/2, 130/2 , headim.size.width   , headim.size.height)];
    _headview.backgroundColor = [UIColor whiteColor];
    _headview.clipsToBounds = YES;
    _headview.layer.cornerRadius = headim.size.width * 0.5;
    [self.view addSubview:_headview];
    
    _phonenum = [self LabelWithRect:CGRectMake(0, _headview.origin.y + _headview.size.height + 10 , SCREEN_WIDTH, 18) textColor:[LCCommon getColor:@"333333"] textstr:@"13810116888" textfont:18 textstyle:NSTextAlignmentCenter];
    [self.view addSubview:_phonenum];
    
    _cert = [UIImage imageNamed:@"home_cret"];
    _notcert = [UIImage imageNamed:@"home_notcret"];
    _certview = [[UIImageView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH/2 - _cert.size.width/2, _phonenum.origin.y + 18 + 10, _cert.size.width, _cert.size.height)];
    [self.view addSubview:_certview];

    
    
    UIButton *serch = [[UIButton alloc]initWithFrame:CGRectMake(50 , _certview.origin.y + _cert.size.height + 35, SCREEN_WIDTH - 100, 45)];
    serch.backgroundColor = [LCCommon getColor:@"f7514a"];
    [serch setTitle:@"央行征信查询" forState:UIControlStateNormal];
    //[serch setTitleColor:[UIColor colorWithWhite:1.0 alpha:.2] forState:UIControlStateNormal];
    serch.titleLabel.font = [UIFont systemFontOfSize:15];
    serch.layer.cornerRadius = 2.5;
    [serch addTarget:self action:@selector(serchpress) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:serch];
    
    UILabel *kaitong = [self LabelWithRect:CGRectMake(SCREEN_WIDTH/2 - 63, serch.frame.origin.y + 45 + 20, 14 * 9, 14) textColor:[LCCommon getColor:@"333333"] textstr:@"还没开通?首次开通" textfont:14 textstyle:NSTextAlignmentCenter];
    kaitong.userInteractionEnabled = YES;
    
    NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:kaitong.text];
    [noteStr addAttribute:NSForegroundColorAttributeName value:[LCCommon getColor:@"33CC99"] range:NSMakeRange(5, 4)];
    [kaitong setAttributedText:noteStr] ;
    [self.view addSubview:kaitong];
    
    UITapGestureRecognizer *res = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(kaitongpress)];
    [kaitong addGestureRecognizer:res];
    
    UILabel *footer = [self LabelWithRect:CGRectMake(0, SCREEN_HEIGHT - 20 - 12 - 64, SCREEN_WIDTH, 12) textColor:[LCCommon getColor:@"cccccc"] textstr:@"数据来源于中国人民银行征信中心" textfont:12 textstyle:NSTextAlignmentCenter];
    [self.view addSubview:footer];
}

- (void)doDone
{
    [self.navigationController pushViewController:[CMMyCenterCtrl initFromSB] animated:YES];
}


#pragma mark - kaitongpress

-(void)kaitongpress{
    LLog(@"kaitongpress");
    CMBankRegistCtrl *bankRegistCtrl = [[CMBankRegistCtrl alloc]init];
    [self.navigationController pushViewController:bankRegistCtrl animated:YES];
}

#pragma mark - serchpress

-(void)serchpress{
    LLog(@"serchpress");
    CMBankLoginCtrl *banklogin = [[CMBankLoginCtrl alloc]init];
    [self.navigationController pushViewController:banklogin animated:YES];
}


#pragma mark - certpress

-(void)certpress{
    LLog(@"certpress");
}


#pragma mark - makelabel


-(UILabel *)LabelWithRect:(CGRect)rect textColor:(UIColor *)color textstr:(NSString *)str textfont:(int)font textstyle:(NSTextAlignment)aligment{
    UILabel *label = [[UILabel alloc] initWithFrame:rect];
    label.textColor = color;
    label.text = str;
    label.font = [UIFont systemFontOfSize:font];
    label.textAlignment = aligment;
    label.numberOfLines = 0;
    return label;
}



-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:YES];
    UIImage *placeim = [UIImage imageNamed:@"head_place"];
    [_headview setImageWithURL:[NSURL URLWithString:[CMLoginManager sharedCMLoginManager].currentUserInfo.headImg] placeholderImage:placeim];
    _phonenum.text = [CMLoginManager sharedCMLoginManager].currentUserInfo.mobile;
    if ([[CMLoginManager sharedCMLoginManager].currentUserInfo.identityStatus isEqualToString:@"0"]) {
        _certview.image = _notcert;
    }else{
        _certview.image = _cert;
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
